package com.wwy.user.controller;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.common.constant.CommonConstant;
import com.common.domain.CommonResult;
import com.wwy.user.module.vo.user.UserSaveVo;
import com.wwy.user.module.vo.user.UserUpdateVo;
import com.wwy.user.module.vo.user.UserVo;
import com.wwy.user.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;


@Api(tags = "用户表接口")
@Validated
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "新增用户表")
    @PostMapping("/user/save")
    public CommonResult save(@RequestBody @Valid UserSaveVo saveVo, @RequestHeader(name = CommonConstant.TOKEN) String token) {
        userService.save(saveVo);
        return CommonResult.success(true);
    }


    @ApiOperation(value = "删除用户表")
    @ApiImplicitParam(name = "id", value = "用户表ID", paramType = "path", required = true, dataTypeClass = String.class)
    @GetMapping("/user/delete/{id}")
    public CommonResult deleteById(@PathVariable String id, @RequestHeader(name = CommonConstant.TOKEN) String token) {
        userService.deleteById(id);
        return CommonResult.success(true);
    }


    @ApiOperation(value = "更新用户表")
    @PostMapping("/user/update")
    public CommonResult updateById(@RequestBody @Valid UserUpdateVo updateVo, @RequestHeader(name = CommonConstant.TOKEN) String token) {
        userService.updateById(updateVo);
        return CommonResult.success(true);
    }


    @ApiOperation(value = "查询用户表")
    @ApiImplicitParam(name = "id", value = "用户表ID", paramType = "path", required = true, dataTypeClass = String.class)
    @GetMapping("/user/info/{id}")
    public CommonResult<UserVo> getById(@PathVariable String id, @RequestHeader(name = CommonConstant.TOKEN) String token) {
        UserVo vo = userService.getById(id);
        return CommonResult.success(vo);
    }

}
